package com.jiazhong.封装;

public class AccountTest {
    public static void main(String[] args) {
        Account account=new Account();
        account.setName("孟浩");
        account.setPassword("123456");
        account.setMoney(0);
        account.info();
    }
}

class Account {
    private String name;
    private int money;
    private String password;

    public Account() {
    }

    public Account(String name, int money, String password) {
        this.name = name;
        this.money = money;
        this.password = password;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length() < 2 || name.length() >4) {
            System.out.println("名字输入有误，我给你抽取一个");
            name = "张三";
        }
        this.name = name;
    }


    public int getMoney() {
        return money;
    }

    public void setMoney(int money) {
        if (money < 20) {
            System.out.println("你太穷了,给你100块");
            money = 100;
        }
        this.money = money;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        if (password.length()!=6){
            System.out.println("密码设置有误，给出默认密码111111");
            password="111111";
        }
        this.password = password;
    }
    public void info(){
        System.out.println("姓名"+getName()+"\n密码"+getPassword()+"\n余额"+getMoney());
    }
}
